package ar.edu.uba.fi.jmit.sender.mock;

import java.util.LinkedList;
import java.util.List;

import ar.edu.uba.fi.jmit.integrationcommons.Event;
import ar.edu.uba.fi.jmit.integrationcommons.MessagePriority;
import ar.edu.uba.fi.jmit.sender.Endpoint;
import ar.edu.uba.fi.jmit.sender.exception.SenderRuntimeException;

public class EndpointMock implements Endpoint {
	
	private List<Event> sentEvents;
	
	private MessagePriority lastSentPriority;
	
	public MessagePriority getLastSentPriority() {
		return lastSentPriority;
	}

	public EndpointMock() {
		super();
		sentEvents = new LinkedList<Event>();
	}

	@Override
	public MessagePriority getDefaultPriority() {
		return MessagePriority.NORMAL;
	}

	@Override
	public void send(Event event) {
		sentEvents.add(event);
	}

	@Override
	public void send(Event event, MessagePriority priority) {
		sentEvents.add(event);
		lastSentPriority = priority;
	}

	@Override
	public void setDefaultPriority(MessagePriority priority) {
		throw new SenderRuntimeException("Not implemented");
	}
	
	public Event getLastSentEvent() {
		if(sentEvents == null || sentEvents.isEmpty()) {
			return null;
		}
		return sentEvents.get(sentEvents.size() - 1);
	}

}
